package com.flynn.rock.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "响应信息")
public class Response<DATA> {

    @Schema(description = "响应码")
    private Integer code;

    @Schema(description = "响应子码")
    private Integer subCode;

    @Schema(description = "响应信息")
    private String message;

    @Schema(description = "响应数据")
    private DATA data;

    public static <DATA> Response<DATA> success(DATA data) {
        Response<DATA> result = new Response<>();
        result.setData(data);
        result.setCode(200);
        result.setSubCode(20000);
        result.setMessage("success");
        return result;
    }

    public static Response<Void> fail(String message) {
        Response<Void> result = new Response<>();
        result.setCode(500);
        result.setSubCode(50000);
        result.setMessage(message);
        return result;
    }
}
